package com.baic.ibase.service.mqtt.handler;

import com.alibaba.fastjson2.JSONObject;
import com.baic.ibase.service.devices.DeviceService;
import com.baic.ibase.service.mqtt.MqttMessageStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;


@Component
public class CommandRequestHandler implements MqttMessageStrategy {
    String commandRegex = "^/ibase-device/([0-9]+)/([0-9]+)/service/command/request$";

    Pattern pattern = Pattern.compile(commandRegex);

    @Autowired
    private DeviceService deviceService;

    @Override
    public boolean support(String topic) {
        return pattern.matcher( topic).matches();
    }

    @Override
    public void handle(JSONObject jsonObject) {
        // todo 代理发送指令
        deviceService.proxyExecuteCommand(jsonObject);
    }
}
